package com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.entity.pojo.WrClockRecord;
import com.mapper.WrClockRecordMapper;
import com.service.ClockService;
import org.bouncycastle.math.ec.ScaleYPointMap;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service("ClockService")
public class ClockServiceImp implements ClockService {

    @Resource
    private WrClockRecordMapper clockRecordMapper;

    @Override
    public int clockIn(Integer userId, Integer schedulingId) {
        if (clockRecordMapper.selectOne(
                new QueryWrapper<WrClockRecord>()
                        .eq("user_id", userId).eq("scheduling_id", schedulingId)
        ) != null) {
            return -1;
        }
        System.out.println(userId);
        System.out.println(schedulingId);
        return clockRecordMapper.insert(
                new WrClockRecord()
                        .setCreateTime(LocalDateTime.now())
                        .setSchedulingId(schedulingId)
                        .setUserId(userId)
                        .setClockTime(LocalDateTime.now())
        );
    }
}
